package com.javasm.transfer.goods;

import com.javasm.domin.entity.goods.*;
import com.javasm.domin.vo.goods.GiftsVo;
import com.javasm.domin.vo.goods.GoodsAdjustVo;
import com.javasm.domin.vo.goods.GoodsVO;
import com.javasm.mapper.goods.BaseBrandMapper;
import com.javasm.mapper.goods.BaseTypeMapper;
import com.javasm.mapper.goods.ColorMapper;
import com.javasm.mapper.goods.ProductMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：Drd
 * @Version：1.0
 * @Date：2022/1/17-19:44
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class GiftsTransfer extends BaseTransfer<Gifts, GiftsVo> {

    private final ColorMapper colorMapper;

    private final BaseBrandMapper baseBrandMapper;

    private final BaseTypeMapper baseTypeMapper;

    private final ProductMapper productMapper;

    public List<GiftsVo> setInfo(List<Gifts> list) {
        List<GiftsVo> giftsVos = super.toVO(list);
        for (int i = 0; i < giftsVos.size(); i++) {
            Gifts gifts = list.get(i);
            //对颜色进行赋值
            Color color = colorMapper.selectById(gifts.getGiftsColor());
            GiftsVo giftsVo = giftsVos.get(i);
            giftsVo.setGiftsColor(color == null ? "" : color.getColorName());
//对品牌进行赋值
            BaseBrand baseBrand = baseBrandMapper.selectById(gifts.getBrandId());
            giftsVo.setBrandId(baseBrand == null ? "" : baseBrand.getBrandName());
//对类别进行赋值
            BaseType baseType = baseTypeMapper.selectById(gifts.getTypeId());
            giftsVo.setTypeId(baseType == null ? "" : baseType.getTypeName());
//对产品信息进行赋值
            Product product = productMapper.selectById(gifts.getProductId());
            giftsVo.setProductId(product == null ? "" : product.getProductName());
            if (gifts.getGiftsStatus() == null) {
                giftsVo.setGiftsStatus("未知");
            } else if (gifts.getGiftsStatus() == 0) {
                giftsVo.setGiftsStatus("失效");
            } else if (gifts.getGiftsStatus() == 1) {
                giftsVo.setGiftsStatus("有效");
            } else {
                giftsVo.setGiftsStatus("未知");
            }
        }
        return giftsVos;
    }

    public GiftsVo set(Gifts gifts) {
      GiftsVo giftsVo = super.toVO(gifts);

            //对颜色进行赋值
            Color color = colorMapper.selectById(gifts.getGiftsColor());
            giftsVo.setGiftsColor(color == null ? "" : color.getColorName());
//对品牌进行赋值
            BaseBrand baseBrand = baseBrandMapper.selectById(gifts.getBrandId());
            giftsVo.setBrandId(baseBrand == null ? "" : baseBrand.getBrandName());
//对类别进行赋值
            BaseType baseType = baseTypeMapper.selectById(gifts.getTypeId());
            giftsVo.setTypeId(baseType == null ? "" : baseType.getTypeName());
//对产品信息进行赋值
            Product product = productMapper.selectById(gifts.getProductId());
            giftsVo.setProductId(product == null ? "" : product.getProductName());
            if (gifts.getGiftsStatus() == null) {
                giftsVo.setGiftsStatus("未知");
            } else if (gifts.getGiftsStatus() == 0) {
                giftsVo.setGiftsStatus("失效");
            } else if (gifts.getGiftsStatus() == 1) {
                giftsVo.setGiftsStatus("有效");
            } else {
                giftsVo.setGiftsStatus("未知");
            }
        return giftsVo;
    }



}
